/*
** xfce-fake.h
*/

#ifndef   	XFCE_FAKE_H_
# define   	XFCE_FAKE_H_

#include <gtk/gtk.h>
#include <glib.h>


#ifndef _
#include <libintl.h>
#define _(String) gettext (String)
#endif

#ifndef N_
#define N_(String) String
#endif



G_BEGIN_DECLS

GtkWidget *xfce_create_framebox(const gchar *title,
                                GtkWidget  **frame_bin);

GtkWidget *xfce_create_framebox_with_content (const gchar *title, 
                                              GtkWidget   *content);


#define xfce_titled_dialog_new_with_buttons gtk_dialog_new_with_buttons
#define XfceTitledDialog GtkDialog
/* to do: implement */
#define xfce_titled_dialog_set_subtitle(...) do {}while(0)

typedef struct XfceRc{
    GKeyFile * file;
    char * filename;
    char * group_name;
} XfceRc;

XfceRc*     xfce_rc_simple_open                 (const gchar *filename,
						 gboolean readonly);

gboolean            xfce_rc_read_bool_entry             (const XfceRc *rc,
                                                         const gchar *key,
                                                         gboolean fallback);


gint                xfce_rc_read_int_entry              (const XfceRc *rc,
                                                         const gchar *key,
                                                         gint fallback);


void                xfce_rc_close                       (XfceRc *rc);


#define xfce_rc_close(rc)						\
    do {								\
	if ( rc->filename )	{					\
	    gsize size;							\
	    char * cont = g_key_file_to_data (rc->file, &size, NULL);	\
	    g_file_set_contents(rc->filename,cont,(gssize)size,NULL);	\
	    g_free(cont);						\
	    g_free(rc->filename);					\
	}								\
	g_free(rc->group_name);						\
	g_key_file_free(rc->file);					\
	g_slice_free(XfceRc, rc);					\
	}								\
    while(0)

static void * xfce_fake_helper;

#define xfce_rc_has_group(rc,group)		\
    g_key_file_has_group(rc->file,group)    

#define xfce_rc_get_keys(rc)						\
    g_key_file_get_keys(rc->file,rc->group_name,NULL,NULL);

#define xfce_rc_write_int_entry(rc,key,value)				\
    g_key_file_set_integer(rc->file,rc->group_name,key,value); 

#define xfce_rc_write_value(rc,key,value)				\
    g_key_file_set_value(rc->file,rc->group_name,key,value); 

#define xfce_rc_write_entry xfce_rc_write_value

#define xfce_rc_write_bool_entry(rc,key,value)				\
    g_key_file_set_boolean(rc->file,rc->group_name,key,value); 

#define xfce_rc_read_value(rc,key)					\
    g_key_file_get_value (rc->file,rc->group_name,key,NULL)


#define xfce_rc_read_entry(rc,key,fallback)				\
    (xfce_fake_helper=g_key_file_get_value((rc)->file,rc->group_name,(key),NULL), \
     xfce_fake_helper ? (gchar *)xfce_fake_helper : (gchar*)(fallback)) \

#define xfce_rc_set_group(rc,name)				\
    do {							\
	g_free(rc->group_name);					\
	rc->group_name=g_strdup(name);				\
    }while(0)

#ifdef DEBUG					
#define DBG(...)				\
    g_fprintf(stderr,__VA_ARGS__)		
#else						
#define DBG(...)				\
    do{}while(0)				
#endif


#define xfce_err(...)							\
    do {								\
	GtkWidget *message = gtk_message_dialog_new(			\
	    NULL, 0,							\
	    GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,__VA_ARGS__);		\
	gtk_dialog_run (GTK_DIALOG (message));				\
	gtk_widget_destroy(message);					\
    } while(0)



#define xfce_textdomain(package,package_localdir,charset)		\
    do {								\
	char * xYZpa3th=g_build_filename(g_getenv("APP_DIR"),package_localdir,NULL); \
	bindtextdomain (package,xYZpa3th);				\
	bind_textdomain_codeset (package, charset);			\
	textdomain (package);						\
	g_free(xYZpa3th);						\
    }									\
    while(0)


#define xfce_exec(cmd,in_terminal,use_sn,error)	\
    g_spawn_command_line_async(cmd,error)


static inline GtkWidget *
xfce_create_panel_button (void)
{
    GtkWidget *button = gtk_button_new ();

    GTK_WIDGET_UNSET_FLAGS (button, GTK_CAN_DEFAULT|GTK_CAN_FOCUS);
    gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
    gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);

    gtk_widget_set_name (button, "xfce_panel_button");

    return button;
}


static inline GtkWidget *
xfce_create_panel_toggle_button (void)
{
    GtkWidget *button = gtk_toggle_button_new ();
    GTK_WIDGET_UNSET_FLAGS (button, GTK_CAN_DEFAULT|GTK_CAN_FOCUS);
    gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
    gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
    gtk_widget_set_name (button, "xfce_panel_toggle_button");
    return button;
}



#define xfce_allow_panel_customization()	\
    TRUE					


#ifdef ROX_PLUGIN_FAKE_FRAMEBOX

GtkWidget *
xfce_create_framebox(const gchar *title,
                     GtkWidget **frame_bin);

GtkWidget* 
xfce_create_framebox_with_content (const gchar *title, GtkWidget *content);

#endif

#ifdef ROX_PLUGIN_FAKE_XFCE_HEADER
GtkWidget*
xfce_create_header_with_image (GtkWidget   *image,
                               const gchar *text);

GtkWidget*
xfce_create_header (GdkPixbuf *icon, const gchar *text);
#endif


G_END_DECLS

#endif 	    /* !XFCE-FAKE_H_ */
